package com.bigluo.util;


import com.bigluo.common.exception.ValidateException;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Collection;

/**
 * Created by luojun on 2017/8/31.
 */
public class Assert {
    public static void isNull (Object t ,String code,String msg) {
        if(t!=null) {
            throw new ValidateException(code,msg);
        }
    }
    public static void notNull(Object t,String code ,String msg) {
        if(t == null ){
            throw new ValidateException(code,msg);
        }
    }
    public static void notEmpty(Collection collection, String code, String msg) {
        if(CollectionUtils.isEmpty(collection)) {
            throw new ValidateException(code,msg);
        }
    }
    public static void isTrue(boolean expression,String code,String msg) {
        if(!expression) {
            throw new ValidateException(code,msg);
        }
    }
    public static void hasText(String t,String code,String msg) {
        if(!StringUtils.hasText(t)) {
            throw new ValidateException(code,msg);
        }
    }
}
